<?php

namespace App\Admin\Eloquent;
use App\Exceptions\BusinessException;
use Router;

class GiftAttr extends Model
{
  /**
   * 实例化模型时, 可批量赋值属性白名单
   *
   * @var array
   */
  protected $fillable = [
      'activity_id', 'key1','key2'
  ];
  public $timestamps = false;
  /**
   * 添加红包活动属性
   */
  public function addAttr($data){
  	$this->where("activity_id","=",$data['activity_id'])->delete();
  	$insert_data=array();
  	foreach ($data['son'] as $key => $value) {
  		$insert_data[]=array('activity_id'=>$data['activity_id'],'name'=>'son_'.$key,'value'=>$value);
      if(isset($data['tou']) && !empty($data['tou'])){
        $insert_data[]=array('activity_id'=>$data['activity_id'],'name'=>'tou_'.$key,'value'=>$data['tou'][$key]);
      }
  	}
    if(isset($data['auto']) && $data['auto']){
      $insert_data[]=array('activity_id'=>$data['activity_id'],'name'=>"auto",'value'=>$data['auto']);
    }
  	return $this->insert($insert_data);
  }
}